//var carturl="http://192.168.1.125:6688";
var carturl="http://cart.spider.com.cn";
var text = "";
/** 购物车 */
function getordercart(){
    if("" != text){
       $("#ltmn2").downMenu(50,".trlcont","open");
       return ;
    }
    var url_remote = "/productmodify.action";
    $.getJSON(url_remote,{
        productType:"second017"
    },function (data){
        if(null != data){
            text = "";
            var list = data;
            for(var i=0;i<list.length;i++){
                var arr = list[i];    
                var objjson = JSON.parse(arr.orderAttributeMap.slice(1,arr.orderAttributeMap.length-1));
                var pic = objjson.picture;
                var name = arr.productName;
                var productid = arr.productId;
                var quantity =  arr.quantity;
                //nums = nums + parseInt(quantity);
                var ptype = arr.productType;
                var urll = "/"+ptype+"/"+productid+".html";
                if(name.length>12){
                    name = name.substring(0,12)+"...";
                }
                text += "<li class=\"clear\">";
                text += "<span class=\"pic fl\">";
                text += "<a href=\""+urll+"\"  target=\"_blank\">";
                text += "<img src=\""+pic+"\" width=\"43\" height=\"43\" alt=\"\">";
                text += "</a>";
                text += "</span>";
                text += "<dl>";
                text += "<dt>";
                text += "<a href=\""+urll+"\" target=\"_blank\" title=\""+arr.productName+"\">"+name+"</a>";
                text += "</dt>";
                text += "<dd>";
                text += "<span class=\"trlrt\"><strong>&yen";
                text += "<em class=\"red2\">"+arr.price+"</em>";
                text += "</strong><a href=\"javascript:void(0)\" onclick=\"delGood(this,'"+productid+"','"+arr.uuid+"','"+quantity+"')\">删除</a>";
                text += "</span>";
                text += "</li>";
            }
            setText(text);   
            $("#ordercartsesul").html(text);
            var num = $("#oheadnum").html();
            $("#trltotl").html("<strong>购物车里有<span id=\"headcanum\">"+(num)+"</span>件商品</strong><a target=\"_blank\" href=\"/spiderCart_cartList.html\" class=\"btn_red1\">查看我的购物车</a>");
        }
    });
}
/** 删除购物车商品 */
function delGood(a,productid,uuid,quantity){
	var map = {};
	map[uuid] = productid;	
	var customerId=$("#hcustomerid").val();
	if(customerId ==""){
		spiderLogin.util.login();
	}
	//向接口发送删除请求
	var datainfo = {
			restful:"delete",
			customerId: customerId,
			deleteProduct: map
	};
	//向接口发送删除请求
	$.ajax({ 
		url: spidercart+"/cart/update",
		type: 'POST',
		contentType: 'application/json',
		dataType:"json",                 
        data:JSON.stringify(datainfo), 
		success: function(data){
			    setText("");
	            var headcanum = $("#headcanum").html();
	            var gditem=$(a).parents("li");
	            gditem.remove();
	            var headcanum = headcanum-quantity;
	            $("#headcanum").html(headcanum);
	            $("#oheadnum").html(headcanum);
		},
		error: function(data){
			alert("系统繁忙");
			return false;
		}
	});
}
function setText(value){
    text = value;
}
$(function(){

/*扩展*/
$.fn.extend({

/*下拉菜单*/
downMenu:function(time,dwntg,css){
		this.mouseenter(function(){
			var menu=$(this);
			var downMenu=menu.find(dwntg);
			dlTime=setTimeout(function(){
				menu.addClass(css);
				downMenu.slideDown(time);
			},100);
		}).mouseleave(function(){
			var menu=$(this);
			var downMenu=menu.find(dwntg);
			clearTimeout(dlTime);
			downMenu.hide();
			menu.removeClass(css);
		})
    }
})

/*弹出绑定框*/
$.fn.extend({
addCard:function(pop){

	var mtop=$(pop).height()/2;
	if($(".mask").length<=0){
		$("body").append("<div class='mask'></div>");
	}
	$(".mask").show();
	$(pop).show().css({"top":"50%","margin-top":-mtop,"position":"fixed"});
	$(pop).find(".close").click(function(event){
		closePop();
		event.preventDefault();
	});
	$(".mask").click(function(){
		closePop();
	})
	function closePop() {
		$(pop).hide();
		$(".mask").hide();
	}
}
})

$.fn.extend({

/*背景移动动画*/
bgPstAnimate:function(nowX,afterX){
	$(this).hover(function(){
		var nowLink=$(this);
		dlTime2=setTimeout(function(){
			nowLink.animate({
				"background-position-x": afterX
			},200)
		},100)
	},function(){
		clearTimeout(dlTime2);
		$(this).animate({
			"background-position-x": nowX
		},200)
	})
}

})


$.fn.extend({

/*鼠标滑过显示弹出*/
showTgPop:function() {
	var nowTag=$(this);
	var nowPop=nowTag.find("p");
	nowPop.hide();
	nowTag.hover(function(){
		tgtime=setTimeout(function(){
			nowPop.slideDown(100);
		},200)
	},function(){
		clearTimeout(tgtime);
		nowPop.slideUp(100);
	})
}

})

$.fn.extend({

/*商品tab展示*/
divTabChange:function(tab,cont){
	var tabZone=$(this);
	var zoneCont=tabZone.find(cont);
	var zoneTab=tabZone.find(tab);
	zoneCont.hide().eq(0).show();
	zoneTab.find("li").eq(0).addClass("on");
	zoneTab.find("li").click(function(){
		zoneTab.find("li").removeClass("on");
		$(this).addClass("on");
		var index=zoneTab.find("li").index(this);
		zoneCont.hide().eq(index).show().css("opacity",0).animate({
			opacity:'1'
		},300);
	})
	zoneTab.find("a").click(function(event){
		event.preventDefault();
	})
}
})


$.fn.extend({

/*商品tab展示_hover*/
divTabChange_hv:function(tab,cont){
	var tabZone=$(this);
	var zoneCont=tabZone.find(cont);
	var zoneTab=tabZone.find(tab);
	zoneCont.hide().eq(0).show();
	zoneTab.find("li").eq(0).addClass("on");
	var deltime;
	zoneTab.find("li").mouseenter(function(){
		$now=$(this);
		var index=zoneTab.find("li").index(this);
		deltime=setTimeout(function(){
			zoneTab.find("li").removeClass("on");
			$now.addClass("on");
			zoneCont.hide().eq(index).show().css("opacity",0).animate({
				opacity:'1'
			},300);
		},100)
	})
	zoneTab.find("li").mouseleave(function() {
		clearTimeout(deltime);
	});
	zoneTab.find("a").click(function(event){
		event.preventDefault();
	})
}
})

$(".goodsArea").divTabChange(".gdTab",".gdWrap");
$(".personIn").divTabChange(".funcTab",".funcWrap");
$(".photoWrap").divTabChange(".phtap",".phtCont");
$(".msgWrap").divTabChange(".msgTab",".msgArea");
$("#msgNew").divTabChange(".msgCty",".msgZone");
$("#msgRead").divTabChange(".msgCty",".msgZone");
$(".yueWrap").divTabChange(".yueTap",".yueArea");
$(".shTypeArea").divTabChange(".shTytab",".shTyShow");
$(".ychArea").divTabChange(".ycharTab",".ycharWp");
$("#paigou").divTabChange_hv(".ttl_tab",".hmwrp");
$("#rktab1").divTabChange_hv(".rkTabqt",".rank");
$("#rktab2").divTabChange_hv(".rkTabqt",".rank");
$("#careChos").divTabChange_hv(".cpetab",".cpetList");
$("#paperPt").divTabChange_hv(".mgztn",".showlist");
$("#goodsPt").divTabChange_hv(".gdstn",".showlist");
$(".shadow_l").divTabChange(".shadow_Head",".shadow_data");
$(".seemover_l").divTabChange(".title",".shadcont");
$(".invitation").divTabChange(".cont",".about");
$("#showPt").divTabChange_hv(".tick",".showlist");


$.fn.extend({

/*商品列表滚屏*/
scrollGoodSet:function(list,mgx,num){
	var sclwrp=$(this);
	var sclWidth = $(this).find(list).width();
	var sclNum = $(this).find(list).find("li").length;
	var sclListlen = Math.ceil($(this).find(list).find("li").length/num)-1;
	var i = 0;
	$(this).find(list).find("ul").css("margin-left","0");
	$(this).find(".prev").hide();
	if(sclNum > num){
		sclwrp.find(".next").show();
	}
	else{
		sclwrp.find(".next").hide();
	}
	$(this).find(".prev").click(function(event) {
		event.preventDefault();
		if(i>0){
			i--;
			if(i==0){
				sclwrp.find(".prev").fadeOut(300);
			}
			sclwrp.find(".next").fadeIn(300);
			turnsclList(i);
		}
	});
	$(this).find(".next").click(function(event) {
		event.preventDefault();
		if(i<sclListlen){
			i++;
			if(i==sclListlen){
				sclwrp.find(".next").fadeOut(300);
			}
			sclwrp.find(".prev").fadeIn(300);
			turnsclList(i);
		}
	});
	function turnsclList(index) {
		var nowLeft = -index*(sclWidth+mgx);
		sclwrp.find(list).find("ul").stop(true,false).animate({"margin-left":nowLeft},200);
	}
}

})


/*最近浏览商品轮换*/
var hstgdHeight = $(".sdlistWrp").height();
var hstscllen = Math.ceil($(".sdlistWrp .clmnList1 li").length/3);
var hstgd_bnr = 0;
var hstgdTimer;

for(var i=0;i<hstscllen;i++){
	$(".dotNav2").append("<li><img width='13' height='13' src='http://www.spider.com.cn/images/common/trans.png' alt=''></li>")
}

$(".dotNav2 li").mouseenter(function() {
	hstgd_bnr = $(".dotNav2 li").index(this);
	hstshowGoods(hstgd_bnr);
}).eq(0).trigger("mouseenter");

$(".sdlistWrp .clmnList1").css("height",hstgdHeight * (hstscllen));

$(".sdlistWrp").hover(function() {
	clearInterval(hstgdTimer);
	},function() {
		hstgdTimer = setInterval(function() {
		hstshowGoods(hstgd_bnr);
		hstgd_bnr++;
		if(hstgd_bnr == hstscllen) {hstgd_bnr = 0;}
	},4000);
}).trigger("mouseleave");

function hstshowGoods(index) {
	var nowTop;
	if(index==0){
		nowTop=0;
	}
	else{
		nowTop = -index*hstgdHeight;
	}
	$(".sdlistWrp .clmnList1").stop(true,false).animate({"margin-top":nowTop},300);
	$(".dotNav2 li").removeClass("on").eq(index).addClass("on");
}

/*图片信息弹出*/
$(".showhold").find(".hold").hide();
var sldTime;
$(".showhold").hover(function(){
	var ngood=$(this);
	sldTime=setTimeout(function(){
		ngood.find(".hold").slideDown(400)
	},100);
},function(){
	clearTimeout(sldTime);
	$(this).find(".hold").slideUp(400);
})

/*栏目切换*/
$(".fesvTab li").mouseenter(function(){
	$(".fesvTab li").removeClass("on");
	$(this).addClass("on");
	var index=$(".fesvTab li").index(this);
	$(".fesvCont").css("display","none").eq(index).fadeIn(500);
})

/*城市切换*/
var nowcity=$("#city .chs").text();
var cityList=$("#city .ctype a");
for(var i=0;i<cityList.length;i++){
	if(cityList.eq(i).text()==nowcity){
		$("#city .ctype a").eq(i).addClass("now");
		break;
	}
}
$("#city .ctype a").click(function(event){
	event.preventDefault();
	var mycity=$(this).text();
	$("#city .chs").text(mycity);
	$("#city .ctype a").removeClass("curr");
	$(this).addClass("curr");
})

/*logo鼠标滑过效果*/
if($(".slogenChg").length>0){
	var nowh2logo=$(".slogenChg").attr("src");
	var imgPosition;
	$(".logo").hover(function(){
		imgPosition=nowh2logo.indexOf("common/")+7;
		var imgName=nowh2logo.slice(imgPosition);
		nowh2logo_new=nowh2logo.replace(imgName,"logo_slogen.gif");
		$(this).find(".slogenChg").attr("src",nowh2logo_new);
	},function(){
		$(this).find(".slogenChg").attr("src",nowh2logo);
	})
}


/*自适应屏幕宽度*/
function winResize() {
	var winWidth=$(window).width();
	var bnrlen = $(".aucShow .gdShow li").length;
	if(winWidth<1200){
		dist=32;
		$("body").addClass("mw980");
		$("#browse").scrollGoodSet(".footList",0,4);
		$("#gpGdList").scrollGoodSet(".gpGoodWrp",1,3);
		setTimeout(function(){
			$("#recommend").scrollGoodSet(".footList",0,4);
		},100000);
		$("#collect").scrollGoodSet(".clltList",48,3);
		$("#myfilm").scrollGoodSet(".itemList",0,3);
		$("#shts1").scrollGoodSet(".shTyWrp",6,3);
		$("#shts2").scrollGoodSet(".shTyWrp",6,3);
		$("#shts3").scrollGoodSet(".shTyWrp",6,3);
		$("#shts4").scrollGoodSet(".shTyWrp",6,3);
		$("#shts5").scrollGoodSet(".shTyWrp",6,3);
		$("#shts6").scrollGoodSet(".shTyWrp",6,3);

		/*礼品众筹banner划屏*/
		function showbnrs2(index){
			var btnLeft = 116*index;
			var nowLeft = -index*574;
			$(".aucShow .gdShow ul").stop().animate({"margin-left":nowLeft},300);
			$(".aucShow .showon").stop().animate({
				left:btnLeft
			},300)
		};

		$(".aucShow .gdShow ul").css("width",574 * (bnrlen));
		$(".aucShow .showon").css("top","0");
		var now_bnr1 = 0;
		$(".gdNav li").mouseenter(function() {

			now_bnr1 = $(".gdNav li").index(this);
			showbnrs2(now_bnr1);
		}).eq(0).trigger("mouseenter");
	}
	else{
		dist=45;
		$("body").removeClass("mw980");
		$("#browse").scrollGoodSet(".footList",9,5);
		$("#gpGdList").scrollGoodSet(".gpGoodWrp",1,4);
		setTimeout(function(){
			$("#recommend").scrollGoodSet(".footList",9,5);
		},100000);
		$("#collect").scrollGoodSet(".clltList",9,3);
		$("#myfilm").scrollGoodSet(".itemList",0,4);
		$("#shts1").scrollGoodSet(".shTyWrp",7,4);
		$("#shts2").scrollGoodSet(".shTyWrp",7,4);
		$("#shts3").scrollGoodSet(".shTyWrp",7,4);
		$("#shts4").scrollGoodSet(".shTyWrp",7,4);
		$("#shts5").scrollGoodSet(".shTyWrp",7,4);
		$("#shts6").scrollGoodSet(".shTyWrp",7,4);

		/*礼品众筹banner划屏*/
		function showbnrs1(index) {
			var	btnTop = 123*index;
			var	nowLeft = -index*608;
			$(".aucShow .gdShow ul").stop().animate({"margin-left":nowLeft},300);
			$(".aucShow .showon").stop().animate({
				top:btnTop
			},300);
		};

		$(".aucShow .gdShow ul").css("width",608 * (bnrlen));
		$(".aucShow .showon").css("left","0");
		var now_bnr2 = 0;
		$(".gdNav li").mouseenter(function() {
			now_bnr2 = $(".gdNav li").index(this);
			showbnrs1(now_bnr2);
		}).eq(0).trigger("mouseenter");

	}

}



/*调用*/
winResize();
$(window).resize(function(){
	winResize();
})

/*-------------下拉菜单--------------*/
$("#magzine .subMenu").downMenu(100,".mnCont","");
$("#present .subMenu").downMenu(100,".mnCont","");
$("#global .subMenu").downMenu(100,".mnCont","");
$(".acctSet").downMenu(20,"ul","open");
$(".typeWrp div").downMenu(100,"ul","on");
$("#city").downMenu(100,".citychs","on");
$("#storeSelector").downMenu(100,".stCity","");
$(".tipoff").downMenu(100,"a","hover");
$(".wuliu").downMenu(100,".prompt","");
$(".receiver").downMenu(100,".getmanPp","");
$("#preview .specList").scrollGoodSet(".specItem",0,4);
/*全站公用*/
$("#ltmn1").downMenu(50,"ul","open");
$("#ltmn2").downMenu(50,".trlcont","open");
$("#ltmn3").downMenu(50,"ul","open");
$("#ltmn4").downMenu(50,"ul","open");
$("#ltmn5").downMenu(50,".shjq","open");
/*鼠标停留弹出层*/
$("#mail").showTgPop();
$("#phon").showTgPop();


/*显示弹出层*/
$(".showpop a").click(function(event){
	if($(".mask").length<=0){
		$("body").append("<div class='mask'></div>");
	}
	var now_i=$(".showpop a").index(this);
	event.preventDefault();
	var nowTab=$(this).text();
	$(".mask").hide();
	var popDiv=$(".photoPop");
	if(popDiv.css("display")=="none"){
		popDiv.show();
		$(".mask").show();
	};
	$(".mask").click(function(){
		closePop();
	});
	$(".photoPop .close").click(function(event){
		closePop();
		event.preventDefault();
	});
	showOpt(now_i);
	function closePop() {
		popDiv.hide();
		$(".mask").hide();
	}
	function showOpt(i) {
		$(".phtap li").removeClass("on").eq(i).addClass("on");
		$(".phtCont").hide().eq(i).show();
	}
})

/*二维码随屏滚动*/
$(window).scroll(function(){
	var dcmscl_height=$(document).scrollTop();
	if(dcmscl_height>620){
		$(".dmsCode").css("top",dcmscl_height);
	}
})
/*关闭二维码*/
$(".dmsClose").click(function(){
	$(".dmsCode").hide();
})



/*头像划过效果*/
$(".portrait a").hide();
$(".portrait").hover(function(){
	$(this).find("a").show();
},function(){
	$(this).find("a").hide();
})

/*左侧菜单开启&关闭*/
$(".menuPart h4").click(function(){
	var mainmenu=$(this);
	var submenu=$(this).siblings("ul");
	var substate=submenu.css("display");
	if(substate=="block"){
		submenu.slideUp(200);
		mainmenu.addClass("close");
	}
	else if(substate=="none"){
		submenu.slideDown(200);
		mainmenu.removeClass("close");
	}
})

/*图片划过效果*/
$(".phtCont table td").not($(".bdnone")).hover(function(){
	$(this).css("border","1px solid #ff4747");
},function(){
	$(this).css("border","1px solid #e5e5e5");
})

/*地址栏划过效果*/
$(".addrList .addtool a").hide();
$(".addrList .close").hide();
$(".addrList li").hover(function(){
	$(this).find(".addtool a").show();
	$(this).find(".close").show();
},
	function(){
	$(this).find(".addtool a").hide();
	$(this).find(".close").hide();
})

/*二级菜单*/
$(".mnList>li").hover(function(){
	var finalDiv=$(this).find(".fnMenuDiv");
	$(this).addClass("on");
	if(finalDiv.css("display")=="none"){
		finalDiv.show();
	}
},function(){
	$(this).removeClass("on");
	$(this).find(".fnMenuDiv").hide();
})

/*图片划屏展示*/
$("#movPicshow").owlCarousel({
    items: 1,
    navigation: false,
    animateOut: 'fadeOut',
    loop: true,
    autoplay:true,
    autoplayTimeout:4000,
    autoplayHoverPause:true
});
$("#showPicshow").owlCarousel({
    items: 1,
    navigation: false,
    animateOut: 'fadeOut',
    loop: true,
    autoplay:true,
    autoplayTimeout:4000,
    autoplayHoverPause:true
});

});
// 书报亭下载引导
var flag=true;
init();
$(".gb").click(function(){
      
      $('.cfc').animate({width:"0%"},1000,function(){
      	$('.cfc').hide();
      	$('.dfc').show();
      });

      });
  $(".dfc").click(function(){
      $('.cfc').show();
      $('.dfc').hide();
      	$('.cfc').animate({width:"100%"},500);

      });
        function init(){
 		if(flag){
 		$('.cfc').show();
      $('.dfc').hide();
      
      	$('.cfc').animate({width:"100%"},500);
      	$('.cfc .pic').animate({display:"none"},600);
          setTimeout(function(){
            $('.cfc').animate({width:"0%"},1000,function(){
      	$('.cfc').hide();
      	$('.dfc').show();
      	 
      });
            init();
          },10000);
          flag=false;
        }
      }
      
   	/**校验非空**/
	function paramIsNotNull(obj){
		if(obj != null && obj != "undefined" && obj != "null" && typeof(obj) != "undefined" && obj != undefined && typeof(obj) != undefined){
			obj = $.trim(obj+"");
			if(obj != ""){
				return true;	
			}else{
				return false;	
			}
		}else{
			return false;	
		}
	}